import request from "@/utils/request";
import type {UserListParams,UserListResponse,SaveUserParams,GetUserRoleListResponse} from './model/userModel'
enum Api {
  getUserListUrl = "/admin/acl/user",
  UserUrl= "/admin/acl/user/save",
  UserAssignUrl="/admin/acl/user/doAssign" ,  // POST
  getUserAclUrl="/admin/acl/user/toAssign/"
  // GET /admin/acl/user/toAssign/{adminId}
}

export const getUserListApi = ({ page, limit, username }:UserListParams) => {
  return request.get<any, UserListResponse>(Api.getUserListUrl + `/${page}/${limit}`, {
    params: {
      username,
    },
  });
};

export const UserUrlApi = (data:SaveUserParams) => {
  return request.post<any, null>(Api.UserUrl,data);
};

//根据用户id获取角色列表
export const getUserRoleListApi = (userId: string) => {
  return request.get<any, GetUserRoleListResponse>(
    Api.getUserAclUrl + `/${userId}`
  );
}


export const UserAssignApi = (userId:string,roleId:string[]) => {
  return request.post<any, null>(Api.UserAssignUrl,{},{
    params:{
      userId,
      roleId:roleId+"",
    }
  });
};